package com.clock.web.controller.shop;

import com.clock.common.annotation.Log;
import com.clock.common.core.controller.BaseController;
import com.clock.common.core.domain.AjaxResult;
import com.clock.common.core.page.TableDataInfo;
import com.clock.common.enums.BusinessType;
import com.clock.common.utils.poi.ExcelUtil;
import com.clock.shop.domain.ShopService;
import com.clock.shop.domain.vo.ShopServiceVo;
import com.clock.shop.service.IShopServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 服务信息Controller
 * 
 * @author ruoyi
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/shop/service")
public class ShopServiceController extends BaseController
{
    @Autowired
    private IShopServiceService shopServiceService;

    /**
     * 查询服务信息列表
     */
    // @PreAuthorize("@ss.hasPermi('shop:service:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopServiceVo shopServiceVo)
    {
        startPage();
        List<ShopServiceVo> list = shopServiceService.selectShopServiceList(shopServiceVo);
        return getDataTable(list);
    }

    /**
     * 导出服务信息列表
     */
    @PreAuthorize("@ss.hasPermi('shop:service:export')")
    @Log(title = "服务信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopServiceVo shopServiceVo)
    {
        List<ShopServiceVo> list = shopServiceService.selectShopServiceList(shopServiceVo);
        ExcelUtil<ShopServiceVo> util = new ExcelUtil<ShopServiceVo>(ShopServiceVo.class);
        util.exportExcel(response, list, "服务信息数据");
    }

    /**
     * 获取服务信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:service:query')")
    @GetMapping(value = "/{serviceId}")
    public AjaxResult getInfo(@PathVariable("serviceId") Long serviceId)
    {
        return success(shopServiceService.selectShopServiceByServiceId(serviceId));
    }

    /**
     * 新增服务信息
     */
    @PreAuthorize("@ss.hasPermi('shop:service:add')")
    @Log(title = "服务信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopServiceVo shopServiceVo)
    {
        return toAjax(shopServiceService.insertShopService(shopServiceVo));
    }

    /**
     * 修改服务信息
     */
    @PreAuthorize("@ss.hasPermi('shop:service:edit')")
    @Log(title = "服务信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopServiceVo shopServiceVo)
    {
        return toAjax(shopServiceService.updateShopService(shopServiceVo));
    }

    /**
     * 删除服务信息
     */
    @PreAuthorize("@ss.hasPermi('shop:service:remove')")
    @Log(title = "服务信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{serviceIds}")
    public AjaxResult remove(@PathVariable Long[] serviceIds)
    {
        return toAjax(shopServiceService.deleteShopServiceByServiceIds(serviceIds));
    }
}
